var moment = require('moment');

module.exports = function (sequelize, DataTypes) {
  var positionArea = sequelize.define('position_area', {
    uuid: {
      type: DataTypes.UUID,
      defaultValue: DataTypes.UUIDV4,
      primaryKey: true
    },
    type: {
      type: DataTypes.BOOLEAN,
      defaultValue: 1,
      get: function () {
        return this.getDataValue('type') * 1;
      }
    }
  }, {
    // 是否需要增加created_at、updated_at、deleted_at字段
    timestamps: true,
    underscored: true,
    // 设置paranoid为true（此种模式下，删除数据时不会进行物理删除，而是设置deleted_at为当前时间
    paranoid: false
  });

  positionArea.associate = function(models) {
    // Using additional options like CASCADE etc for demonstration
    // Can also simply do Task.belongsTo(models.User);
    // User.belongsTo(models.xxx, {
    //   // onDelete: 'CASCADE',
    // });
    models.position.belongsToMany(models.area, { through: positionArea });
    models.area.belongsToMany(models.position, { through: positionArea });
  };

  return positionArea;
};

